<?php
/**
 * Description of 
 *
 * @author Marco Mounzer
 * @email m.mounzer@gmail.com
 * @copyright 2013
 */
require_once '../lib/begin.php';

if (isset($_POST['username']) && isset($_POST['password'])) {
    $user = WebUser::FindUser($_POST['username'], $_POST['password']);
    if ($user !== false) {
        $_SESSION['user'] = $user;

        header('location: /admin/cars.php');
        die;
    }
}
if (isset($_SESSION['user']) && get_class($_SESSION['user']) == 'WebUser'){
    header('location: /admin/cars.php');
    die;
}

require_once '_header.php';
?>

<form action="" method="post">
    <table align="center">            
        <thead>
            <tr>
                <th colspan="2">Login</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <th>Username</th>
                <td><input type="text" id="username" name="username" value="<?php echo isset($_POST['username']) ? $_POST['username'] : ''; ?>" /></td>
            </tr>
            <tr>
                <th>Password</th>
                <td><input type="password" id="password" name="password" value="" /></td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <td colspan="2">
                    <input type="hidden" id="action" name="action" value="login" />
                    <input type="submit" id="submit" name="submit" value="Login" />
                </td>
            </tr>
        </tfoot>
    </table>
</form>
<?php
require_once '_footer.php';
?>